import lxml.etree as le
with open('edu.html','r',encoding='utf-8') as f:
    # 读取本地的edu.html
    html = f.read()
    # 把html转换成xml对象
    html_x = le.HTML(html)
    # 得到6个div对象
    div_x_s = html_x.xpath('//div[@class="classify_cList"]')
    # 构造数据存储对象
    data_s = []
    # 对6个包含1级分类和2级分类对象做遍历
    for div_x in div_x_s:
        # 得到1级分类
        category1 = div_x.xpath('./h3/a/text()')[0]
        # 得到这个1级分类下的所有2级分类
        category2_s = div_x.xpath('./div/span/a/text()')
        # 添加数据到存储对象
        data_s.append(
            dict(
                category1 = category1,
                category2_s = category2_s
            )
        )
        # 打印data_s
        # print(data_s)
        # 对data_s进行遍历打印
        for data in data_s:
            print(data.get('category1'))
            for category2 in data.get('category2_s'):
                print('   ',category2)
